package game.roles.enemys;

import game.frame.MainFrame;
import game.roles.bullets.FireBullet;
import game.roles.bullets.StarBullet;
import game.roles.visual.BackgroundMaps;
import game.utils.ImageChange;

import java.awt.*;
import java.util.Random;

/**
 * @author liuyulai
 * Created with IntelliJ IDEA.
 * Date: 21.5.11
 * Time: 9:52
 * Description: 最后的boss
 */
public class Boss2 extends EnemyRole implements Bosses {
    public static Image[] boss2Images;

    private ImageChange rm = new ImageChange(3);

    private int count = 0;

    /**
     * 向前走
     */
    private final int GO = 0;

    /**
     * 向后走
     */
    private final int BACK = 1;

    private int direction = 0;

    public Boss2() {
        super(2000, 250, 300, 300, 10000, 500);
    }

    @Override
    public void drawRole(Graphics graphics) {
        super.drawRole(graphics);
        graphics.setColor(Color.GREEN);
        graphics.drawRect(this.x, this.y - 20, this.width, 10);
        graphics.fillRect(this.x, this.y - 20, (int) (this.hp * 1.0 / this.maxHp * this.width), 10);
    }

    @Override
    public void rolesMove() {
        this.img = rm.change(boss2Images);
        if (direction == GO) {
            this.x -= 2;
            if (this.x < 1500) {
                direction = BACK;
            }
        }

        if (direction == BACK) {
            this.x += 2;
            if (this.x > 1700) {
                direction = GO;
            }
        }


        count++;
        if (new Random().nextBoolean()) {
            if (count > 150) {
                attack();
            }
        } else {
            if (count > 170) {
                attack2();
            }
            if (count > 190) {
                count = 0;
            }

        }
    }

    public void attack() {
        MainFrame.roleList.add(new StarBullet(this.x + 10, this.y + 130, StarBullet.LEFT_UP));
        MainFrame.roleList.add(new StarBullet(this.x + 10, this.y + 130, StarBullet.LEFT_DOWN));
        MainFrame.roleList.add(new StarBullet(this.x, this.y + new Random().nextInt(40) + 140, StarBullet.FRONT));
        MainFrame.roleList.add(new StarBullet(this.x + 10, this.y + 130, StarBullet.LEFT_UP));
        MainFrame.roleList.add(new StarBullet(this.x + 10, this.y + 130, StarBullet.LEFT_DOWN));
    }

    public void attack2() {
        MainFrame.roleList.add(new FireBullet(this.x + 20, this.y + 140, FireBullet.LEFT_UP_UP));
        MainFrame.roleList.add(new FireBullet(this.x + 20, this.y + 140, FireBullet.LEFT_DOWN_DOWN));
        MainFrame.roleList.add(new FireBullet(this.x + 20, this.y + 120, FireBullet.FRONT));
    }

    @Override
    public void byHit(int deHp) {
        this.hp -= deHp;
        //怪物死亡时将怪物直接移除集合
        if (this.hp <= 0) {
            MainFrame.playerExp += this.exp;
            MainFrame.roleList.remove(this);
            System.out.println("boss死了");
            BackgroundMaps.mapMoveOrNot = true;
            setBoomWay();
        }
    }

//    /**
//     * 击败boss后判定为成功
//     */
//    @Override
//    public void setBoomWay() {
//        super.setBoomWay();
//        MainFrame.flag = false;
//        MainFrame.isPass = true;
//    }
}
